//
//  ByShopDetailProductInfoCell.m
//  hutouben_ios
//
//  Created by pro on 16/11/29.
//  Copyright © 2016年 mc. All rights reserved.
//

#import "ByShopDetailProductInfoCell.h"

#pragma mark - layout
@implementation ByShopDetailProductInfoCellLayout

- (void)setModel:(ByNetProductDetailModel *)model {
    
    _model = model;
    
    CGFloat x, y, width, height;
    
    // 1.标题
    x       = 10;
    y       = 10;
    width   = SCREEN_WIDTH - x * 2;
    height  = [model.title getRectOfStringWithSize:CGSizeMake(width, 1000) font:15].size.height;
    height  = MAX(height, 20);
    self.titleFrame = CGRectMake(x, y, width, height);
    
    // 2.属性
    x       = 10;
    y       = CGRectGetMaxY(self.titleFrame) + 5;
    width   = SCREEN_WIDTH - x * 2;
    height  = 20;
    self.attrFrame = CGRectMake(x, y, width, height);
    
    // 3.线条
    x       = 10;
    y       = CGRectGetMaxY(self.attrFrame) + 10;
    width   = SCREEN_WIDTH - x * 2;
    height  = 0.5;
    self.lineFrame = CGRectMake(x, y, width, height);
    
    // 4.价格
    x       = 10;
    y       = CGRectGetMaxY(self.lineFrame) + 10;
    width   = SCREEN_WIDTH - x * 2;
    height  = 20;
    self.priceFrame = CGRectMake(x, y, width, height);

    // 5.cell
    x       = 0;
    y       = 0;
    width   = SCREEN_WIDTH;
    height  = CGRectGetMaxY(self.priceFrame) + 10;
    self.cellFrame = CGRectMake(x, y, width, height);
}

@end



#pragma mark - cell
@implementation ByShopDetailProductInfoCell
{
    UILabel *_titleLabel;       // 标题
    UILabel *_attrLabel;        // 属性
    UILabel *_line;             // 线
    UILabel *_priceLabel;       // 价格
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
 
    // 标题
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.adjustsFontSizeToFitWidth = YES;
    _titleLabel.numberOfLines = 0;
    _titleLabel.font = FONT(15);
    _titleLabel.textColor = TEXT_COLOR;
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_titleLabel];
    
    // 属性
    _attrLabel = [[UILabel alloc] init];
    _attrLabel.font = FONT(14);
    _attrLabel.textColor = [UIColor lightGrayColor];
    _attrLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_attrLabel];
    
    // 线
    _line = [[UILabel alloc] init];
    _line.backgroundColor = ZJ_SEPLINE_COLOR;
    [self.contentView addSubview:_line];
    
    // 价格
    _priceLabel = [[UILabel alloc] init];
    _priceLabel.adjustsFontSizeToFitWidth = YES;
    _priceLabel.font = FONT(18);
    _priceLabel.textColor = HTB_THEME_COLOR;
    _priceLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_priceLabel];

}

- (void)setLayout:(ByShopDetailProductInfoCellLayout *)layout {
    
    _layout = layout;
    
    [self setNeedsLayout];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    ByNetProductDetailModel *model = _layout.model;
    
    // 设置布局
    _titleLabel.frame   = _layout.titleFrame;
    _attrLabel.frame    = _layout.attrFrame;
    _line.frame         = _layout.lineFrame;
    _priceLabel.frame   = _layout.priceFrame;
    
    // 设置属性
    _titleLabel.text    = model.title;
    _attrLabel.text     = model.attr;
    _priceLabel.text    = [NSString stringWithFormat:@"￥%@", model.price];
}

@end
